package com.acwing.partition20;

import java.io.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;

/**
 * @author `RKC`
 * @date 2022/1/12 20:03
 */
public class AC1969品种邻近 {

    private static final int N = 50010;
    private static int[] nums = new int[N];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        n = Integer.parseInt(s[0]);
        int k = Integer.parseInt(s[1]);
        for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(reader.readLine().split("\\s+")[0]);
        writer.write(resolve(k) + "\n");
        writer.flush();
    }

    private static int resolve(int k) {
        Queue<Integer> queue = new LinkedList<>();
        int answer = -1;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            if (map.containsKey(nums[i])) answer = Math.max(answer, nums[i]);
            map.put(nums[i], map.getOrDefault(nums[i], 0) + 1);
            queue.add(nums[i]);
            if (queue.size() > k) map.remove(queue.poll());
        }
        return answer;
    }
}
